<?php
/**
 * Created by PhpStorm.
 * Author: 芸签cms www.yunqiancms.com
 * User: sun
 * Date: 2022/8/17
 * Time: 4:19 PM
 */
namespace app\backend\modules\sys\controllers;

use app\backend\controllers\BaseController;
use app\backend\modules\sys\services\PluginMarketService;

class PluginMarketController extends BaseController
{
    public function index(){
        return view("backend.sys.pluginMarket.index");
    }
    public function getList(){
        $search = request()->search;
        $list = (new PluginMarketService())->getList($search);
        return $this->successJson('',$list);
    }
    public function detail(){
        return view("backend.sys.pluginMarket.detail");
    }
    public function getDetail(){
        $id = intval(request()->id);
        $domain = request()->getHttpHost();
        $result = (new PluginMarketService())->getDetail($id, $domain);

        return $this->successJson('',$result);
    }
    public function install(){
        $pluginData = request()->plugin;
        $domain = request()->getHttpHost();
        (new PluginMarketService())->install($domain, $pluginData);
        return $this->successJson('安装成功');
    }
    public function batchInstall(){
        $pluginDatas = request()->plugins;
        $domain = request()->getHttpHost();
        $res = (new PluginMarketService())->batchInstall($domain, $pluginDatas);
        return $this->successJson('安装成功:'.$res['success'].'个，安装失败:'.$res['fail'].'个');
    }
}